/**
 * 初始化简历数量供应数据
 */
define(function(){
    var ec=require('echarts');
    require('echarts/chart/chord');
    require('echarts/chart/force');
    
    var ecConfig = require('echarts/config');
    var zrUtil = require('zrender/tool/util');
    var zrnumber = require('echarts/util/number');
    
    var myChart_chord= ec.init(document.getElementById('quantity_chord_source'));

    var option_chord = {
    tooltip : {
        trigger: 'item',
        formatter: function (params) {
            if (params.indicator2) {    // is edge
                return params.indicator2 + ' ' + params.name + ' ' + params.indicator;
            } else {    // is node
                return params.name
            }
        }
    },
    toolbox: {
        show : true,
        orient:'vertical',
        y:'bottom',
        feature : {
            restore : {show: true},
            magicType: {show: true, type: ['force', 'chord']},
            saveAsImage : {show: true}
        }
    },
    legend: {
        x: 'left',
        data:['北京人事/行政/后勤']
    },
    series : [
        	{
            type:'chord',
            sort : 'ascending',
            sortSub : 'descending',
            showScale : false,
            itemStyle : {
                normal : {
                    label : {
                        rotate : true
                    }
                }
                },
            // 使用 nodes links 表达和弦图
            nodes: [
                {name:'北京销售'},// 此处手动修改
                   {name:'北京'},					
					 {name:'天津'},
					 {name:'深圳'},
					 {name:'石家庄'},
					 {name:'上海'},
					 {name:'太原'},
					 {name:'郑州'},
					 {name:'广州'},
					 {name:'哈尔滨'},
					 {name:'成都'},
					 {name:'武汉'},
					 {name:'济南'},
					 {name:'沈阳'},
					 {name:'长春'},
					 {name:'福州'},
					 {name:'合肥'},
					 {name:'青岛'},
					 {name:'大连'},
					 {name:'苏州'},
					 {name:'重庆'},
					 {name:'杭州'},
					 {name:'长沙'},
					 {name:'东莞'},
					 {name:'南京'},
					 {name:'无锡'},
					 {name:'厦门'},
					 {name:'南宁'},
					 {name:'缺口'}
					            ],
            links: [
                 {source: '北京销售', target: '北京', weight: 63, name: '职位'},			
				{source: '北京销售', target: '天津', weight: 63, name: '职位'},
				{source: '北京销售', target: '深圳', weight: 63, name: '职位'},
				{source: '北京销售', target: '石家庄', weight: 63, name: '职位'},
				{source: '北京销售', target: '上海', weight: 63, name: '职位'},
				{source: '北京销售', target: '太原', weight: 63, name: '职位'},
				{source: '北京销售', target: '郑州', weight: 63, name: '职位'},
				{source: '北京销售', target: '广州', weight: 63, name: '职位'},
				{source: '北京销售', target: '哈尔滨', weight: 63, name: '职位'},
				{source: '北京销售', target: '成都', weight: 63, name: '职位'},
				{source: '北京销售', target: '武汉', weight: 63, name: '职位'},
				{source: '北京销售', target: '济南', weight: 63, name: '职位'},
				{source: '北京销售', target: '沈阳', weight: 63, name: '职位'},
				{source: '北京销售', target: '长春', weight: 63, name: '职位'},
				{source: '北京销售', target: '福州', weight: 63, name: '职位'},
				{source: '北京销售', target: '合肥', weight: 63, name: '职位'},
				{source: '北京销售', target: '青岛', weight: 63, name: '职位'},
				{source: '北京销售', target: '大连', weight: 63, name: '职位'},
				{source: '北京销售', target: '苏州', weight: 63, name: '职位'},
				{source: '北京销售', target: '重庆', weight: 63, name: '职位'},
				{source: '北京销售', target: '杭州', weight: 63, name: '职位'},
				{source: '北京销售', target: '长沙', weight: 63, name: '职位'},
				{source: '北京销售', target: '东莞', weight: 63, name: '职位'},
				{source: '北京销售', target: '南京', weight: 63, name: '职位'},
				{source: '北京销售', target: '无锡', weight: 63, name: '职位'},
				{source: '北京销售', target: '厦门', weight: 63, name: '职位'},
				{source: '北京销售', target: '南宁', weight: 63, name: '职位'},
				{source: '北京销售', target: '缺口', weight: 63, name: '职位'},

                // Ribbon Type 的和弦图每一对节点之间必须是双向边
                {target: '北京销售', source: '北京', weight: 890},			
				{target: '北京销售', source: '天津', weight: 5},
				{target: '北京销售', source: '深圳', weight: 4},
				{target: '北京销售', source: '石家庄', weight: 3},
				{target: '北京销售', source: '上海', weight: 3},
				{target: '北京销售', source: '太原', weight: 3},
				{target: '北京销售', source: '郑州', weight: 2},
				{target: '北京销售', source: '广州', weight: 2},
				{target: '北京销售', source: '哈尔滨', weight: 2},
				{target: '北京销售', source: '成都', weight: 2},
				{target: '北京销售', source: '武汉', weight: 2},
				{target: '北京销售', source: '济南', weight: 1},
				{target: '北京销售', source: '沈阳', weight: 1},
				{target: '北京销售', source: '长春', weight: 1},
				{target: '北京销售', source: '福州', weight: 1},
				{target: '北京销售', source: '合肥', weight: 1},
				{target: '北京销售', source: '青岛', weight: 1},
				{target: '北京销售', source: '大连', weight: 1},
				{target: '北京销售', source: '苏州', weight: 1},
				{target: '北京销售', source: '重庆', weight: 1},
				{target: '北京销售', source: '杭州', weight: 1},
				{target: '北京销售', source: '长沙', weight: 1},
				{target: '北京销售', source: '东莞', weight: 1},
				{target: '北京销售', source: '南京', weight: 0},
				{target: '北京销售', source: '无锡', weight: 0},
				{target: '北京销售', source: '厦门', weight: 0},
				{target: '北京销售', source: '南宁', weight: 0},
				{target: '北京销售', source: '缺口', weight: 368}
            ]
        }
    ]
};
                    
   
    /**
     * 根据指标显示日数据
     * @param eventType= 2:第一次加载, 1:切换日，周 刷新 
     */
	function showChord(eventType){
		
		var dateGrp = $('#Quantity_provision_Option').attr('dateGrp');
		var beginDate = $('#beginDate').val();
		 
		var city_option = $('#city_quantity_option').val();
		var cate_option = $('#cate_quantity_option').val();		

        myChart_chord.showLoading({
            text: '正在努力的读取数据中...'
        });
	
	    $.ajax({
	        	url: '/dashboard/resume/ajax/getResumeQuantity',
	        	type: 'POST',
	       		async: true,
	        	data:{"city_option":city_option,"cate_option":cate_option, "dateGroup":dateGrp,"beginDate":beginDate},
	        	dataType: 'json',
	         	success: function(data, textStatus) {
	               	                 		
	                 //设置和弦图
	                 setChord(data);
	                    
	         //		 myChart_chord.setOption(option_chord,true);
             //      myChart_chord.hideLoading();
	                 if(data.links_Array.length==0)
	                 {
	                 	myChart_chord.showLoading({
                      		text: '您好，该日暂无数据...'
                            });
	                 }
	                  	                 
	             },
	             timeout: 5000,
	             error: function() {
	                  myChart_chord.hideLoading();
	             }
	          });        
		  
		
		 //myChart_chord.setOption(option_chord,true);
}

//设置和弦图数据
	function setChord(initalData){

		    $('#beginDate').val(initalData.beginDate);
              
        	option_chord.series[0].nodes=initalData.nodes_Array;
            option_chord.series[0].links= initalData.links_Array;
            
            option_chord.legend.data=initalData.legend;
                             
    //      option_pie.options.push(option);                           
   //       option_pie.series[0].data = data.dataList;                           
      
            myChart_chord.setOption(option_chord,true);
            myChart_chord.hideLoading();
	}
	
  
	 //时间选择事件
    $('#beginDate').datepicker(datepicker_op);
    
    //日周切换
	$(":button.btn_quantityProvision[dateGrp]").click(function(){
            changeDateGrp(this);  
            EC.showChord(1);
        });
        
    //绑定刷新
    $("#refresh_quantity_chord_btn").click(function(){
            showChord();
        });
 
        
     var EC={
            showChord:showChord,
            resize:function(){myChart_chord.resize()}                
        };
      
        return EC;
});